import React from 'react'
import { NavContent, Link } from '../../ui-components'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { fetchProfileTemplateFields, fetchProfileTemplates } from '../../actions/system.action'
import { fetchDocuments, resetOnboardingTemplate } from '../../actions/onboarding.hr.action'
import * as reorgActions from '../../actions/reorg.action'

import { fetchUserProfile, fetchUserCoreProfile, resetUser, fetchReportLineInfo } from '../../actions/user.action'
import { fetchTeamData, resetTeam } from '../../actions/team.action'
import { fetchAtList, clearAtList } from '../../actions/home.action'

const navs = [
	[
    {name: 'onboarding/hr/onboardingFlows?hasApproved=0', show:'入职管理'}, 
    {name: 'employ-managements/1', show:'转正管理'}, 
    {name: 'transfer', show:'调岗管理'}, 
    {name: 'employ-managements/2', show:'离职管理'}, 
	] 
]

export default
@connect(null, dispatch => ({actions: bindActionCreators({ fetchProfileTemplates, fetchDocuments, resetOnboardingTemplate, ...reorgActions, fetchUserCoreProfile, fetchUserProfile, resetUser, fetchAtList, clearAtList, fetchTeamData, resetTeam, fetchProfileTemplateFields, fetchReportLineInfo }, dispatch)}))
class Reorg extends React.Component {

	static contextTypes = {
		router: React.PropTypes.object
	}

	item = ({name, show, active, index}) => (
		<Link 
			to={`#/reorg/${name}`}
      active={
        ~name.indexOf('onboarding')? (~this.props.location.pathname.indexOf(name.split('/')[0]) && active): (
          ~this.props.location.pathname.indexOf(name) && active
        )
      } 
			size="16" 
			label={show}/>
	)

	render() {
		return (
			<NavContent 
				navs={navs} 
				item={this.item}
				{...this.props.actions}
				{...this.context}
			>
				{ this.props.children }
			</NavContent>
		)
	}
}
